package com.zhang.redis.common.util;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.*;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * key的序列化用了string，所以redisTemplate的K一定用string
 *
 * @author zhangFanJun
 * @date 2023-11-30 13:41
 **/
@Slf4j
@RequiredArgsConstructor
@Component
public class RedisManager<T> {

    @Resource
    private  RedisTemplate<String, T> redisTemplate;
    private final RedisValueOpsManager<T> redisValueOpsManager;
    private final RedisHashOpsManager<T> redisHashOpsManager;

    public Boolean delete(String key) {
        return redisTemplate.delete(key);
    }

    public RedisTemplate<String, T> template(){
        return redisTemplate;
    }

    public RedisValueOpsManager<T> keyValue(){
        return redisValueOpsManager;
    }

    public RedisHashOpsManager<T> hash(){
        return redisHashOpsManager;
    }

    public ValueOperations<String,T> getValueOps(){
        return redisTemplate.opsForValue();
    }

    public<T> HashOperations<String,String,T> getHashOps(){
        return redisTemplate.opsForHash();
    }

    public GeoOperations<String,T> getGeoOps(){
        return redisTemplate.opsForGeo();
    }

    public ListOperations<String,T> getListOps(){
        return redisTemplate.opsForList();
    }

    public SetOperations<String,T> getSetOps(){
        return redisTemplate.opsForSet();
    }

    public ZSetOperations<String,T> getZSetOps(){
        return redisTemplate.opsForZSet();
    }
}
